package com.itheima.demo2;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpClient {
    public static void main(String[] args) throws IOException {
        //定义插口对象
        Socket socket = new Socket("127.0.0.1", 10086);
        Scanner sc = new Scanner(System.in);




        System.out.println("客户端发送:");
        //循环输入数据
        while (true) {

            String next = sc.next();

            //判断输入数据是否为over true:跳出循环 false:循环继续
            if(next.equals("over"))break;

            //定义写入对象流
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

            //往服务端传输数据
            bufferedWriter.write(next);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }

        //清理套接字
        socket.close();
    }
}
